class AdministratorsController < ApplicationController

  before_filter :admin_authorize

  def index
    @administrators = User.find_administrators
  end

  def new
    @administrator = User.new
  end

  def create
    @administrator = User.new(params[:administrator])
    @administrator.account_type = 'administrator'

    if @administrator.save
      redirect_to(:action => 'index')
    else
      render :action => 'new'
    end
  end

  def destroy
    if session[:user_id].to_s != params[:id]
      User.destroy(params[:id])
      redirect_to(:action => 'index')
    else
      flash[:notice] = t('flash.cannot_delete_yourself')
      redirect_to :action => 'index'
    end
  end

  private

  def admin_authorize
    head :forbidden if !current_user.is_administrator
  end

end
